package sorter;
import java.rmi.RemoteException;
import java.rmi.server.*;

public class BubbleSort extends UnicastRemoteObject implements ISorter
{
	protected BubbleSort() throws RemoteException {
		super();
	}

	@Override
	public Comparable[] sort(Comparable[] c)
	{
		Comparable[] d = c;
		for (int i = d.length; --i>=0; ) 
		{
		    for (int j = 0; j<i; j++) 
		    {
				if(d[j]instanceof Integer)
				{
					if ((Integer)d[j] > (Integer)d[j+1]) 
					{
					    int a = (Integer)d[j];
					    d[j] = d[j+1];
					    d[j+1] = a;
					}
				}
				
				else if(d[j]instanceof String)
				{
					String b;
					if (((String) d[j]).length() == ((String) d[j+1]).length())
					{
						if(d[j].compareTo(d[j+1]) > 0)
						{
							b = (String)d[j];
						    d[j] = d[j+1];
						    d[j+1] = b;
						}
					}
					else if (((String) d[j]).length() > ((String) d[j+1]).length())
					{
						b = (String)d[j];
						d[j] = d[j+1];
						d[j+1] = b;
					}
				}
		    }
        }
		return d;
	}
}
